package com.system.run.controller;


import com.system.run.entity.User;
import com.system.run.from.Row;
import com.system.run.service.UserService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-12-20
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login/{username}/{password}")
    public Row login(
            @ApiParam(name = "username", value = "用户名",required = false) @PathVariable String username,
            @ApiParam(name = "password", value = "密码",required = false) @PathVariable String password){
        User user = userService.FindByUsername(username);
        if (user == null){
            return Row.ERROR();
        }
        if (password.equals(user.getPassword())){
            return Row.SUCCESS();
        }else{
            return Row.ERROR();
        }
    }

    @PostMapping("login")
    public Row register(
            @ApiParam(name = "username", value = "用户名",required = false) @PathVariable String username,
            @ApiParam(name = "password", value = "密码",required = false) @PathVariable String password){
        User user = userService.FindByUsername(username);
        if (user == null){
            return Row.ERROR();
        }
        if (password.equals(user.getPassword())){
            return Row.SUCCESS();
        }else{
            return Row.ERROR();
        }
    }

}

